//
//  Base.m
//  Lesson H1
//
//  Created by dllo on 15/10/19.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "Base.h"

@implementation Base

// 1. KVC的纠错方法
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
}

- (id)valueForUndefinedKey:(NSString *)key
{
    return nil;
}

// 2. 便利构造器
+ (instancetype)modelWithDic:(NSDictionary *)dic
{
    // 1. self 谁调用这个方法, self就是谁
    // 2. 多态: 父类的指针可以指向子类对象
    id base = [[self alloc] init];
    [base setValuesForKeysWithDictionary:dic];
    return base;
}

+ (NSArray *)modelWithArray:(NSArray *)dicArray
{
    NSMutableArray *array = [NSMutableArray array];
    for (NSDictionary *dic in dicArray) {
        Base *base = [self modelWithDic:dic];
        [array addObject:base];
    }
    return array;
}

@end
